package View;

	import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.JButton;

import Entity.CustomerCard;

	import java.awt.Font;
/**this class provide the GUI window for the salesman to search a customer to update his card*/
	public class SearchCustomerHistoryView extends JFrame {

		private static final long serialVersionUID = 42L;
		/**required  fields and buttons */
		JTextField IdField;
		 JTable table;
		 JButton SearchBtn;
		 JButton BackBtn;
		 JComboBox comboCustomer;
		 
		/** default and only constructor */
		public SearchCustomerHistoryView() {
			getContentPane().setLayout(null);
			setResizable(false);

			this.setLocationRelativeTo(null); 
			this.setTitle("Search Customer Card");
			this.setSize(436, 265);

			JLabel lblCustumerId = new JLabel("CustomerID");
			lblCustumerId.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblCustumerId.setBounds(73, 75, 109, 20);
			getContentPane().add(lblCustumerId);
			

			comboCustomer = new JComboBox(CustomerCard.getCustomersStringArr());
			//comboCustomer = new JComboBox();
			comboCustomer.setBounds(192, 78, 142, 17);
			comboCustomer.addActionListener(comboCustomer);
			getContentPane().add(comboCustomer);
			
			SearchBtn = new JButton("Search");
			SearchBtn.setFont(new Font("Tahoma", Font.BOLD, 15));
			SearchBtn.setBounds(262, 169, 135, 28);
			getContentPane().add(SearchBtn);
			

		
			BackBtn = new JButton("Back");
			BackBtn.setFont(new Font("Tahoma", Font.BOLD, 15));
			BackBtn.setBounds(59, 169, 135, 28);
			getContentPane().add(BackBtn);
			
			JLabel lblSearchCustomerId = new JLabel("Choose Customer ID in order see his card ");
			lblSearchCustomerId.setFont(new Font("Tahoma", Font.BOLD, 13));
			lblSearchCustomerId.setBounds(73, 27, 284, 20);
			getContentPane().add(lblSearchCustomerId);
		}
		/**
		 * function that sets the list of customers
		 * @param listOfCustomers
		 */
		public void setCustomers(String[] listOfCustomers){
			comboCustomer = new JComboBox<String>(listOfCustomers);
			comboCustomer.addActionListener(comboCustomer);
		}
		/**
		 * add listeners to the buttons
		 * @param actionListener
		 */
		public void updateCustomerListener(ActionListener actionListener){
			SearchBtn.addActionListener(actionListener);
			BackBtn.addActionListener(actionListener);		
		}
		
		/**
		 * show and hide window functions
		 */
		public void showWindow(){
			setVisible(true);
		}
		public void hideWindow(){
			setVisible(false);
		}
		
		/**
		 * 
		 * @return buttons functions 
		 */
		public JButton getSearchBtn()
		{
			return this.SearchBtn;
		}
		public JButton getBackBtn()
		{
			return this.BackBtn;
		}



		/**
		 * set fields functions
		 */
		public void  setCUstomer(){
			comboCustomer.setSelectedItem(" ");
		}
		
		/**
		 * clear fields function
		 */
		public void clearFields(){
			comboCustomer.setSelectedItem(" ");
		}
		
		/**
		 * @return AddressField Text 
		 */
		public String getCUstomer(){
			return (String) comboCustomer.getSelectedItem();
		}

		
	}



